﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Calendario.ascx.cs" Inherits="WebControls_Calendario" %>

<script src="js/jquery/plugins/repeater/jsRepeater.js" type="text/javascript"></script>

<script type="text/javascript">
        var gAnio,gMes, gDia;
        var gListaEventos;
        var gIndex;
        
        $(document).ready(function() {
            gAnio = 0;
            gMes = 0;
            gDia = 0;
            gIndex = 0;
            
            $("#<%=this.btnSiguiente.ClientID %>").hide();
            $("#<%=this.btnAnterior.ClientID %>").hide();
  
            buscarEventos(<%=DateTime.Now.Year%>,<%=DateTime.Now.Month%>,<%=DateTime.Now.Day%>);
        });
        
        function buscarEventos(anio,mes,dia){
            
            //numeroSobre('dia_'+ dia + '_sobre','dia_'+ dia);
            if ((gAnio != anio) || (gMes != mes) || (gDia != dia)){
                gAnio = anio;
                gMes = mes;
                gDia = dia;
                $('#tablaEventos').hide();
                $.ajax({
                    type: "GET",
                    url: "QueryAjax/QueryListaEvento.aspx",
                    data: "anio=" + anio + "&mes=" + mes + "&dia=" + dia,
                    success: function(eventos){
                          if (eventos != ""){
                              var listaEventos = eval(eventos);
                              gListaEventos = listaEventos;
                              gIndex = 0;

                              $('#tablaEventos').fillTemplate(eval(listaEventos[0])[gIndex]);
                             
                              $("#<%=this.btnAnterior.ClientID %>").hide();
                              $("#<%=this.btnSiguiente.ClientID %>").hide();
                                
                              if (eval(gListaEventos[0]).length > 0)
                                $('#tablaEventos').show();      
                                                        
                              if (eval(gListaEventos[0]).length > 1)
                                $("#<%=this.btnSiguiente.ClientID %>").show();
                              
                          }else{
                          }
                        }
                });
            }
            return false;
        }
        
        function proximoEvento(avance){
            
            gIndex += avance;
            if (gIndex < 0)
                gIndex = 0;
                
            if (gIndex == 0)
                $("#<%=this.btnAnterior.ClientID %>").hide();
            else
                $("#<%=this.btnAnterior.ClientID %>").show();

            if (gIndex == (eval(gListaEventos[0]).length - 1))
                $("#<%=this.btnSiguiente.ClientID %>").hide();
                
            if (gIndex < eval(gListaEventos[0]).length - 1 && eval(gListaEventos[0]).length > 1)
                $("#<%=this.btnSiguiente.ClientID %>").show();
                
            if (gIndex < eval(gListaEventos[0]).length){
                $('#tablaEventos').fillTemplate(eval(gListaEventos[0])[gIndex]);
            }
            return false;
        }
         
        function numeroSobre(estiloNuevo,estiloViejo){
            $('.' + estiloViejo).removeClass(estiloViejo).addClass(estiloNuevo);
        }
      
</script>

<asp:Table ID="tablaDiaActual" runat="server">
    <asp:TableRow runat="server">
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
    </asp:TableRow>
</asp:Table>
<asp:Table ID="tablaCalendario" runat="server" Height="120px" Width="1px" BorderWidth="0px">
    <asp:TableRow runat="server">
        <asp:TableCell runat="server" RowSpan="6"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server" RowSpan="6"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server" RowSpan="6"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server" RowSpan="6"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server" RowSpan="6"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server" RowSpan="6"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server" RowSpan="6"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server" RowSpan="6"></asp:TableCell>
    </asp:TableRow>
    <asp:TableRow runat="server">
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
    </asp:TableRow>
    <asp:TableRow runat="server">
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
    </asp:TableRow>
    <asp:TableRow runat="server">
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
    </asp:TableRow>
    <asp:TableRow runat="server">
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
    </asp:TableRow>
    <asp:TableRow runat="server">
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
        <asp:TableCell runat="server"></asp:TableCell>
    </asp:TableRow>
</asp:Table>
<br />
<table width="206" style="height: 84px" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            <table width="206" style="height: 74px" cellpadding="0" cellspacing="0">
                <tr>
                    <td>
                        <%--                        <asp:Repeater ID="Repeater1" runat="server">
                            <ItemTemplate>--%>
                        <div id="tablaEventos">
                            <table width="206" style="height: 74px" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td>
                                        <%--<%# DataBinder.Eval(Container.DataItem, "Titulo") %>--%>
                                        ${titulo}
                                    </td>
                                </tr>
                                <tr>
                                    <td class="agenda_texto">
                                        <%--<%# DataBinder.Eval(Container.DataItem, "Descripcion") %>--%>
                                        ${detalle}
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <%--                            </ItemTemplate>
                        </asp:Repeater>--%>
                    </td>
                </tr>
            </table>
            <table width="206" style="height: 10px" cellpadding="0" cellspacing="0">
                <tr align="center">
                    <td style="width: 69px; height: 19px;">
                        <asp:ImageButton OnClientClick="javascript:return proximoEvento(-1);" ImageUrl="~/images/calendario/img_flechaAnterior.jpg"
                            ID="btnAnterior" runat="server" /></td>
                    <td style="width: 68px; height: 19px;">
                        <asp:Label ID="lblPaginas" runat="server" Text=""></asp:Label></td>
                    <td style="width: 69px; height: 19px;">
                        <asp:ImageButton OnClientClick="javascript:return proximoEvento(+1);" ImageUrl="~/images/calendario/img_flechaSiguiente.jpg"
                            ID="btnSiguiente" runat="server" /></td>
                </tr>
            </table>
        </td>
    </tr>
</table>
